﻿using System;
using System.Linq;
using Diploma.Models.IRepositories;

namespace Diploma.Models.Repositories
{
    internal class SubOrderPracticeRepository : ISubOrderPracticeRepository
    {
        private readonly DiplomaEntities dataContext;

        public SubOrderPracticeRepository(DiplomaEntities dataContext)
        {
            this.dataContext = dataContext;
        }

        public SubOrderPractice Get(Guid subOrderId)
        {
            SubOrderPractice subOrder = dataContext.SubOrderPractices.FirstOrDefault(r => r.Id == subOrderId);
            if (subOrder == null)
                throw new Exception("Can't find sub order");
            return subOrder;
        }

        public void SaveChanges()
        {
            dataContext.SaveChanges();
        }
    }
}